//
//  DHWeatherView.m
//  DHKuaiYi
//
//  Created by 韩旭 on 16/11/13.
//  Copyright © 2016年 30-陈辉华. All rights reserved.
//

#import "DHWeatherView.h"
#import "Masonry.h"
#import <UIImageView+WebCache.h>
@interface DHWeatherView()

/* 天气图片 */
@property (strong, nonatomic) UIImageView *weatherImg;
/* 阴晴label */
@property (strong, nonatomic) UILabel *weatherLabel;
/*城市label */
@property (strong, nonatomic) UILabel *cityLabel;
/* 中间分区image */
@property (strong, nonatomic) UIImageView *centerImg;
/* 温度 */
@property (strong, nonatomic) UILabel *temperatureLabel;
/* 时间 */
@property (strong, nonatomic) UILabel *timeLabel;

@end

@implementation DHWeatherView

- (void)xhhSetupSubviews
{
    [super xhhSetupSubviews];
    self.backgroundColor = [UIColor XHH_colorWithHex:0xE6F6F9];
    [self setupUI];
}

-(void)setupUI{
    /*---------- 屏幕适配计算 ----------*/
    //计算比例
    CGFloat sOne = (float)40 / 375;
    CGFloat sThree = (float)1 / 375;
    CGFloat sFour = (float)5 / 375;
    CGFloat sEight = (float)17 / 375;
    
    CGFloat sTwo = (float)60 / 667;
    CGFloat sFive = (float)5 / 667;
    CGFloat sSeven = (float)12 / 667;
    CGFloat sSix = (float)8 / 667;
    
    //margin
    CGFloat sOneMargin = sOne * viewWidth;
    CGFloat sThreeMargin = sThree * viewWidth;
    CGFloat sFourMargin = sFour * viewWidth;
    CGFloat sEightMargin = sEight * viewWidth;
    
    CGFloat sTwoMargin = sTwo * viewHeight;
    CGFloat sFiveMargin = sFive * viewHeight;
    CGFloat sSevenMargin = sSeven * viewHeight;
    CGFloat sSixMargin = sSix * viewWidth;
    
    //实例化
    UIImageView *weatherImg = [[UIImageView alloc]init];
    weatherImg.image = [UIImage imageNamed:@"sun.jpg"];
    CGSize weatherImgSize =CGSizeMake(sOneMargin, sOneMargin);
    
    UILabel *weatherLabel = [[UILabel alloc]init];
    weatherLabel.text = @"晴";
    weatherLabel.textColor =[UIColor XHH_colorWithHex:0x2FC5C5];
    weatherLabel.font = [UIFont systemFontOfSize:sEightMargin];
    
    UILabel *cityLabel = [[UILabel alloc]init];
    cityLabel.text = @"深圳市";
    cityLabel.textColor =[UIColor XHH_colorWithHex:0x2FC5C5];
    cityLabel.font = [UIFont systemFontOfSize:sEightMargin];
    
    UIImageView *centerImg = [[UIImageView alloc]init];
    centerImg.image = [UIImage imageNamed:@"ic_fack_keyboard_btn_send.jog"];
    CGSize centerImgSize = CGSizeMake(sThreeMargin, sTwoMargin);
    
    UILabel *temperatureLabel = [[UILabel alloc]init];
    temperatureLabel.text = @"温度: 0~~22C";
    temperatureLabel.textColor =[UIColor XHH_colorWithHex:0x2FC5C5];
    temperatureLabel.font =[UIFont systemFontOfSize:sSevenMargin];
    
    UILabel *timeLabel = [[UILabel alloc]init];
    timeLabel.text = @"2016年11月11日";
    timeLabel.font = [UIFont systemFontOfSize:sSevenMargin];
    timeLabel.textColor =[UIColor XHH_colorWithHex:0x2FC5C5];

    [self addSubview:weatherImg];
    [self addSubview:weatherLabel];
    [self addSubview:cityLabel];
    [self addSubview:centerImg];
    [self addSubview:temperatureLabel];
    [self addSubview:timeLabel];
    
    //自动布局
    [weatherImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(sFiveMargin * 3);
        make.left.mas_equalTo(self).offset(sFourMargin * 3);
        make.size.mas_equalTo(weatherImgSize);
    }];
    [weatherLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(self);
        make.left.mas_equalTo(weatherImg.mas_right).offset(sFourMargin);
    }];
    [cityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(self);
        make.left.mas_equalTo(weatherLabel.mas_right).offset(sFourMargin * 2);
    }];
    [centerImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(sSixMargin);
        make.centerX.mas_equalTo(self);
        make.size.mas_equalTo(centerImgSize);
    }];
    [temperatureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).offset(sFiveMargin * 3);
        make.left.mas_equalTo(centerImg.mas_right).offset(sFourMargin * 5);
    }];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(temperatureLabel.mas_bottom).offset(sSixMargin);
        make.left.mas_equalTo(centerImg.mas_right).offset(sFourMargin * 5);
    }];
    
    //记录
    self.weatherImg = weatherImg;
    self.weatherLabel = weatherLabel;
    self.cityLabel = cityLabel;
    self.centerImg = centerImg;
    self.temperatureLabel = temperatureLabel;
    self.timeLabel = timeLabel;
}

- (void)setWeatherModel:(DHWeatherModel *)weatherModel {
    
    _weatherModel = weatherModel;
    self.weatherLabel.text = weatherModel.weather;
    self.timeLabel.text = weatherModel.date;
    self.temperatureLabel.text = weatherModel.temperature;
    NSURL *URL = [NSURL URLWithString:weatherModel.dayPictureUrl];
    [self.weatherImg sd_setImageWithURL:URL placeholderImage:[UIImage imageNamed:@"sun.jpg"]];
}
@end










